package com.cos.controller;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cos.commons.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cos.entity.AddressEntity;
import com.cos.service.AddressService;




/**
 * 
 *
 * @author lyc
 * @email 2102@qq.com
 * @date 2021-07-19 22:00:48
 */
@RestController
@RequestMapping("/address")
public class AddressController {
    @Autowired
    private AddressService addressService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public List<AddressEntity> list(@RequestParam("uid") Integer uid){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("uid",uid);
        List<AddressEntity> list = addressService.list(queryWrapper);
        return list;
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		AddressEntity address = addressService.getById(id);

        return R.success();
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AddressEntity address){
		addressService.save(address);

        return R.success();
    }

    @RequestMapping("/getAddressById")
    public AddressEntity getAddressById(@RequestParam("id") Integer id){
        AddressEntity byId = addressService.getById(id);
        return byId;
    }


    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AddressEntity address){
		addressService.updateById(address);

        return R.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		addressService.removeByIds(Arrays.asList(ids));

        return R.success();
    }

}
